#ifndef DEMO_MAPGENERATOR_HPP
#define DEMO_MAPGENERATOR_HPP

#include <types.hpp>
#include "QPoint"

namespace Data { class IEditableGlobalMap; }

namespace Demo {


/*
 * enum for marking array (for Diamond-Square algorithm)
 */
enum DSMark
{
    DSMark_EDGE,
    DSMark_SQUARE,
    DSMark_DIAMOND
};


class MapGeneratorOptions
{
public:
    enum LandscapeMethod {
        LandscapeNone,
        LandscapeAprilRandom,
        LandscapeMidpointDisplacement,
        LandscapeDiamondSquare
    };

    uint width;
    uint height;
    LandscapeMethod landscapeMethod;

    MapGeneratorOptions() :
        width(32),
        height(32),
        landscapeMethod(LandscapeNone)
    {}
};

class TileGenerator;

class MapGenerator
{
public:
    MapGenerator(const MapGeneratorOptions &options);
    ~MapGenerator();

    void generate(Data::IEditableGlobalMap &map) const;

private:
    void generateHeightMapDeprecated(Data::IEditableGlobalMap &map) const;
    void generateHeightMapWithMidpointDisplacement(Data::IEditableGlobalMap &map) const;
    void generateHeightMapWithDiamondSquare(Data::IEditableGlobalMap &map) const;

    void mpdis(QPoint edge1,QPoint edge2,QPoint edge3,QPoint edge4)const;

    void DSAlg()const;
    void DSAAlias()const;
    void squareStep(QPoint edge1,QPoint edge2,QPoint edge3,QPoint edge4)const;
    void diamondStep(QPoint edge1,QPoint edge2,QPoint edge3,QPoint edge4)const;

    float hat(QPoint point)const;
    void shat(QPoint point,float h)const;

    MapGeneratorOptions _options;
    TileGenerator *_tileGen;

    float _roughness;

    mutable std::vector<float>  _heightMap;
};

} // namespace Demo

#endif // DEMO_MAPGENERATOR_HPP
